<?php 	
	header('Access-Control-Allow-Origin: *');
	header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
	header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE');
	include('connect.php');

	// $name = 'guo';
	// $pwd = md5('linyu');
	$name = $_POST['name'];
	$pwd = md5($_POST['pwd']);
	$user = $_POST['user'];

	$sql = 'select id from admin where user="'.$user.'"';
	$result = $db->query($sql);

	$rows = [];
	if($result->num_rows > 0){
		while($row = $result->fetch_array(MYSQLI_ASSOC)){
			$rows[] = $row;
		}
	}

	$id = $rows[0]['id'];
	
	$sql = 'update admin set user="'.$name.'",password="'.$pwd.'" where id='.$id;
	
	$result = $db->query($sql);

	if($result){
		$rows['code'] = '20000';
		$rows['msg'] = '修改成功';
	}else{
		$rows['code'] = '20001';
		$rows['msg'] = '修改失败';
	}

	echo json_encode($rows);